package com.yxzz.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
//import com.ruoyi.system.domain.PHealthHistory;
//import com.ruoyi.system.service.IPHealthHistoryService;
import com.yxzz.core.domain.PHealthHistory;
import com.yxzz.core.service.IPHealthHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 病人健康史Controller
 *
 * @author ruoyi
 * @date 2023-02-28
 */
@RestController
@RequestMapping("/health")
public class PHealthHistoryController extends BaseController
{
    @Autowired
    private IPHealthHistoryService pHealthHistoryService;

    /**
     * 查询病人健康史列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PHealthHistory pHealthHistory)
    {
        startPage();
        List<PHealthHistory> list = pHealthHistoryService.selectPHealthHistoryList(pHealthHistory);
        return getDataTable(list);
    }

    /**
     * 导出病人健康史列表
     */
    @Log(title = "病人健康史", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PHealthHistory pHealthHistory)
    {
        List<PHealthHistory> list = pHealthHistoryService.selectPHealthHistoryList(pHealthHistory);
        ExcelUtil<PHealthHistory> util = new ExcelUtil<PHealthHistory>(PHealthHistory.class);
        util.exportExcel(response, list, "病人健康史数据");
    }

    /**
     * 获取病人健康史详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pHealthHistoryService.selectPHealthHistoryById(id));
    }

    /**
     * 新增病人健康史
     */
    @Log(title = "病人健康史", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PHealthHistory pHealthHistory)
    {
        return toAjax(pHealthHistoryService.insertPHealthHistory(pHealthHistory));
    }

    /**
     * 修改病人健康史
     */
    @Log(title = "病人健康史", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PHealthHistory pHealthHistory)
    {
        return toAjax(pHealthHistoryService.updatePHealthHistory(pHealthHistory));
    }

    /**
     * 删除病人健康史
     */
    @Log(title = "病人健康史", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pHealthHistoryService.deletePHealthHistoryByIds(ids));
    }
}
